using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.MedicalDomain;
using ShivamEMR.Model.DataInterfaces.MedicalDataInterf;
using ShivamEMR.Data.Repositories.MedicalRepo;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Medical.Controllers
{   
    public class DiseaseController : Controller
    {
		private readonly IDiseaseCategoryRepository diseasecategoryRepository;
		private readonly IDiseaseGroupRepository diseasegroupRepository;
		private readonly IDiseaseRepository diseaseRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public DiseaseController() //: this(new DiseaseCategoryRepository(), new DiseaseGroupRepository(), new DiseaseRepository())
        {
            //this.diseasecategoryRepository=Registry.RepositoryFactory.ge
        }

        public DiseaseController(IDiseaseCategoryRepository diseasecategoryRepository, IDiseaseGroupRepository diseasegroupRepository, IDiseaseRepository diseaseRepository)
        {
			this.diseasecategoryRepository = diseasecategoryRepository;
			this.diseasegroupRepository = diseasegroupRepository;
			this.diseaseRepository = diseaseRepository;
        }

        //
        // GET: /Disease/

        public ViewResult Index()
        {
            return View(diseaseRepository.All);//Including(disease => disease.Category, disease => disease.Group, disease => disease.Children, disease => disease.Diagnosises));
        }

        //
        // GET: /Disease/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(diseaseRepository.Find(id));
        }

        //
        // GET: /Disease/Create

        public ActionResult Create()
        {
			ViewBag.PossibleCategories = diseasecategoryRepository.All;
			ViewBag.PossibleGroups = diseasegroupRepository.All;
            return View();
        } 

        //
        // POST: /Disease/Create

        [HttpPost]
        public ActionResult Create(Disease disease)
        {
            if (ModelState.IsValid) {
                diseaseRepository.InsertOrUpdate(disease);
                diseaseRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleCategories = diseasecategoryRepository.All;
				ViewBag.PossibleGroups = diseasegroupRepository.All;
				return View();
			}
        }
        
        //
        // GET: /Disease/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleCategories = diseasecategoryRepository.All;
			ViewBag.PossibleGroups = diseasegroupRepository.All;
             return View(diseaseRepository.Find(id));
        }

        //
        // POST: /Disease/Edit/5

        [HttpPost]
        public ActionResult Edit(Disease disease)
        {
            if (ModelState.IsValid) {
                diseaseRepository.InsertOrUpdate(disease);
                diseaseRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleCategories = diseasecategoryRepository.All;
				ViewBag.PossibleGroups = diseasegroupRepository.All;
				return View();
			}
        }

        //
        // GET: /Disease/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(diseaseRepository.Find(id));
        }

        //
        // POST: /Disease/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var d = diseaseRepository.Find(id);
            diseaseRepository.Delete(d);
            diseaseRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

